

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/hello_lixi.gitee.io/img/fluid.png">
  <link rel="icon" href="/hello_lixi.gitee.io/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Mr.LI">
  <meta name="keywords" content="">
  
    <meta name="description" content="MapStruct工具转换entity和VO，实现PO和VO的互转">
<meta property="og:type" content="article">
<meta property="og:title" content="MapStruct工具转换entity和VO">
<meta property="og:url" content="https://xistudycode.gitee.io/hello_lixi.gitee.io/2022/12/31/MapStruct%E5%AE%9E%E7%8E%B0jo%E8%BD%ACvo/index.html">
<meta property="og:site_name" content="Welcome to the technology blog">
<meta property="og:description" content="MapStruct工具转换entity和VO，实现PO和VO的互转">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110316577.png">
<meta property="og:image" content="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110239234.png">
<meta property="og:image" content="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110347521.png">
<meta property="og:image" content="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110444077.png">
<meta property="article:published_time" content="2022-12-31T03:05:17.381Z">
<meta property="article:modified_time" content="2022-12-31T06:22:02.790Z">
<meta property="article:author" content="Mr.LI">
<meta property="article:tag" content="MapStruct">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110316577.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>MapStruct工具转换entity和VO - Welcome to the technology blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/hello_lixi.gitee.io/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/hello_lixi.gitee.io/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/hello_lixi.gitee.io/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"xistudycode.gitee.io","root":"/hello_lixi.gitee.io/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/hello_lixi.gitee.io/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/hello_lixi.gitee.io/js/utils.js" ></script>
  <script  src="/hello_lixi.gitee.io/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/hello_lixi.gitee.io/">
      <strong>xBlog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hello_lixi.gitee.io/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hello_lixi.gitee.io/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hello_lixi.gitee.io/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hello_lixi.gitee.io/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hello_lixi.gitee.io/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/hello_lixi.gitee.io/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="MapStruct工具转换entity和VO"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Mr.LI
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-12-31 11:05" pubdate>
          2022年12月31日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.6k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          31 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">MapStruct工具转换entity和VO</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2022年12月31日 下午
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p><strong>entity 转换 VO</strong></p>
<p>1、pom.xml 导入依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs xml">    <span class="hljs-comment">&lt;!--这个可加可不加，不加也能运行</span><br><span class="hljs-comment">org.mapstruct.mapstruct-jdk8: 1.2.0.Final版本以后, 已废弃, 改回用mapstruct包. 可以参考&quot;使用手册&quot;.</span><br><span class="hljs-comment">        &lt;dependency&gt;</span><br><span class="hljs-comment">            &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;</span><br><span class="hljs-comment">            &lt;artifactId&gt;mapstruct-jdk8&lt;/artifactId&gt;</span><br><span class="hljs-comment">            &lt;version&gt;1.5.3.Final&lt;/version&gt;</span><br><span class="hljs-comment">        &lt;/dependency&gt;</span><br><span class="hljs-comment">--&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mapstruct<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mapstruct-processor<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.5.3.Final<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>provided<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br>        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mapstruct<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mapstruct<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.5.3.Final<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br>//注意版本，学习视频中的版本不能再自己的项目中运行，试着升级成最新版本，可以运行<br></code></pre></td></tr></table></figure>

<p>2、自定义接口</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.southwind.mapper;<br><br><span class="hljs-keyword">import</span> com.southwind.entity.Category;<br><span class="hljs-keyword">import</span> com.southwind.entity.Product;<br><span class="hljs-keyword">import</span> com.southwind.vo.OrderVO;<br><span class="hljs-keyword">import</span> com.southwind.vo.ProductVO;<br><span class="hljs-keyword">import</span> org.mapstruct.Mapper;<br><span class="hljs-keyword">import</span> org.mapstruct.Mapping;<br><span class="hljs-keyword">import</span> org.mapstruct.Mappings;<br><span class="hljs-keyword">import</span> org.mapstruct.Named;<br><span class="hljs-keyword">import</span> org.mapstruct.factory.Mappers;<br><br><span class="hljs-keyword">import</span> java.util.List;<br><br><span class="hljs-meta">@Mapper</span>  <span class="hljs-comment">//注意是依赖mapstruct里面的mapper，不要选错了</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">ProductMapper</span> &#123;<br><br>    <span class="hljs-type">ProductMapper</span> <span class="hljs-variable">mapper</span> <span class="hljs-operator">=</span> Mappers.getMapper(ProductMapper.class);<br><br>    <span class="hljs-comment">//自动生成实现类，在实现类中，使用product的get方法获取product的值，调用ProductVO的set方法赋值</span><br>    <span class="hljs-meta">@Mappings(&#123;</span><br><span class="hljs-meta">            @Mapping(source = &quot;productId&quot;,target = &quot;id&quot;),</span><br><span class="hljs-meta">            @Mapping(source = &quot;productName&quot;,target = &quot;name&quot;),</span><br><span class="hljs-meta">            @Mapping(source = &quot;productPrice&quot;,target = &quot;price&quot;),</span><br><span class="hljs-meta">            @Mapping(source = &quot;productStatus&quot;,target = &quot;status&quot;,qualifiedByName = &quot;convertStatus&quot;)//qualifiedByName转换的时候调用此方法</span><br><span class="hljs-meta">    &#125;)</span><br>    ProductVO <span class="hljs-title function_">pojo2vo</span><span class="hljs-params">(Product product)</span>;<br><br>    <span class="hljs-comment">//自定义方法，将product里面的intiger类型的转换成boolean类型(1是true，0是false)，直接转会造成类型转换错误，接口中不允许有方法实现类，因此是default方法类型，jdk8允许接口中有默认方法</span><br>    <span class="hljs-meta">@Named(&quot;convertStatus&quot;)</span><br>    <span class="hljs-keyword">default</span> Boolean <span class="hljs-title function_">convertStatus</span><span class="hljs-params">(Integer status)</span>&#123;<br>        <span class="hljs-keyword">if</span>(status == <span class="hljs-number">1</span>)<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>    &#125;<br><br>    <span class="hljs-comment">//生成的实现类中自动调用pojo2vo进行遍历Productlist进行赋值</span><br>    List&lt;ProductVO&gt; <span class="hljs-title function_">list2vo</span><span class="hljs-params">(List&lt;Product&gt; list)</span>;<br><br>    <span class="hljs-comment">//将两个实体的属性合为一个VO类中，OrderVO中同时包含product.productName和category.categoryName</span><br>    <span class="hljs-meta">@Mappings(&#123;</span><br><span class="hljs-meta">            @Mapping(source = &quot;product.productName&quot;,target = &quot;product&quot;),</span><br><span class="hljs-meta">            @Mapping(source = &quot;category.categoryName&quot;,target = &quot;category&quot;)</span><br><span class="hljs-meta">    &#125;)</span><br>    OrderVO <span class="hljs-title function_">createOrder</span><span class="hljs-params">(Product product, Category category)</span>;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110316577.png" srcset="/hello_lixi.gitee.io/img/loading.gif" lazyload alt="image-20221231110316577"></p>
<img src="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110239234.png" srcset="/hello_lixi.gitee.io/img/loading.gif" lazyload alt="image-20221231110239234" style="zoom:80%;" />



<p><img src="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110347521.png" srcset="/hello_lixi.gitee.io/img/loading.gif" lazyload alt="image-20221231110347521"></p>
<img src="https://raw.githubusercontent.com/hellelixi/note-image01/main/images/image-20221231110444077.png" srcset="/hello_lixi.gitee.io/img/loading.gif" lazyload alt="image-20221231110444077" style="zoom:80%;" />





<p>3、测试类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.southwind.mapper;<br><br><span class="hljs-keyword">import</span> com.southwind.entity.Category;<br><span class="hljs-keyword">import</span> com.southwind.entity.Product;<br><span class="hljs-keyword">import</span> com.southwind.vo.OrderVO;<br><span class="hljs-keyword">import</span> com.southwind.vo.ProductVO;<br><span class="hljs-keyword">import</span> org.junit.Test;<br><span class="hljs-keyword">import</span> org.springframework.beans.BeanUtils;<br><br><span class="hljs-keyword">import</span> java.math.BigDecimal;<br><span class="hljs-keyword">import</span> java.util.ArrayList;<br><span class="hljs-keyword">import</span> java.util.List;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">VOTest</span> &#123;<br><br>    <span class="hljs-meta">@Test</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">test</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-type">Product</span> <span class="hljs-variable">product</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Product</span>(<span class="hljs-number">1</span>,<span class="hljs-string">&quot;电脑&quot;</span>, <span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-number">6000</span>),<span class="hljs-number">1</span>);<br>        <span class="hljs-type">ProductVO</span> <span class="hljs-variable">productVO</span> <span class="hljs-operator">=</span> ProductMapper.mapper.pojo2vo(product);<br>        System.out.println(productVO);<br>    &#125;<br><br>    <span class="hljs-meta">@Test</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">list</span><span class="hljs-params">()</span>&#123;<br>        List&lt;Product&gt; list = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">3</span>; i++) &#123;<br>            list.add(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Product</span>(i,<span class="hljs-string">&quot;电脑&quot;</span>+i,<span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-number">6000</span>),<span class="hljs-number">1</span>));<br>        &#125;<br>        List&lt;ProductVO&gt; productVOS = ProductMapper.mapper.list2vo(list);<br>        <span class="hljs-keyword">for</span> (ProductVO productVO : productVOS) &#123;<br>            System.out.println(productVO);<br>        &#125;<br>    &#125;<br><br>    <span class="hljs-meta">@Test</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">order</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-type">Product</span> <span class="hljs-variable">product</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Product</span>(<span class="hljs-number">1</span>, <span class="hljs-string">&quot;电脑&quot;</span>, <span class="hljs-keyword">new</span> <span class="hljs-title class_">BigDecimal</span>(<span class="hljs-number">6000</span>),<span class="hljs-number">1</span>);<br>        <span class="hljs-type">Category</span> <span class="hljs-variable">category</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Category</span>(<span class="hljs-string">&quot;电子产品&quot;</span>);<br>        <span class="hljs-type">OrderVO</span> <span class="hljs-variable">order</span> <span class="hljs-operator">=</span> ProductMapper.mapper.createOrder(product, category);<br>        System.out.println(order);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<p>学习视频：<a target="_blank" rel="noopener" href="https://www.bilibili.com/video/av890087747/?vd_source=557547c5067fdc048e1e4d8565fba06b">https://www.bilibili.com/video/av890087747/?vd_source=557547c5067fdc048e1e4d8565fba06b</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/hello_lixi.gitee.io/categories/java%E5%BC%80%E5%8F%91/" class="category-chain-item">java开发</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/hello_lixi.gitee.io/tags/MapStruct/">#MapStruct</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>MapStruct工具转换entity和VO</div>
      <div>https://xistudycode.gitee.io/hello_lixi.gitee.io/2022/12/31/MapStruct实现jo转vo/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Mr.LI</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年12月31日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/hello_lixi.gitee.io/2023/02/10/SpringCloud%E9%A1%B9%E7%9B%AE%E9%9B%86%E6%88%90nacos%E5%90%AF%E5%8A%A8%E6%8A%A5%E9%94%99/" title="SpringCloud项目集成nacos启动报错,Failed to configure a DataSource url attribute is not specified and no embedded datasource could be configured">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">SpringCloud项目集成nacos启动报错,Failed to configure a DataSource url attribute is not specified and no embedded datasource could be configured</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/hello_lixi.gitee.io/2022/12/29/MyBatisPlu%E5%A4%9A%E6%95%B0%E6%8D%AE%E6%BA%90%E5%8A%A8%E6%80%81%E5%88%87%E6%8D%A2/" title="MyBatis-Plu多数据源动态切换">
                        <span class="hidden-mobile">MyBatis-Plu多数据源动态切换</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>xBolg</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>@Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/hello_lixi.gitee.io/js/events.js" ></script>
<script  src="/hello_lixi.gitee.io/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/hello_lixi.gitee.io/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/hello_lixi.gitee.io/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/hello_lixi.gitee.io/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
